The ultimate torch switch is probably a "push on - push off" switch. You would press the switch once to turn the light on and again to turn it off again. (I had a torch like this too!). In digital circuit terms I am talking about a "flip flop" which you flip from one state to another by sending a clock pulse.
This is the most complicated flow diagram so far. We can break it down to the following steps:
-
Set up the hardware
-
Wait for the button to go down
-
Flip the state of the LED
-
Wait for the button to go up
-
Go back to step 2
I flip the state of the LED by turning if off if it is on and vice versa. You can convince yourself the program works by going through it by hand.
When a program gets larger a complete flow diagram becomes harder to write and make sense of. In that case I often create a list as above which describes the steps my program will go through. Different programmers have their own ideas on what is meaningful. I suggest that you use what works for you!
